﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;



namespace EyesSaver
{
    

    public partial class NotificationForm : Form
    {
        public const int XTab = 50;
        public const int YTab = 50;

        private Boolean prevenClose = false;

        private int waitTimeMs = 5 * 60 * 1000;

        public NotificationForm(int waitTimeMs, Boolean prevenClose)
        {
            this.waitTimeMs = waitTimeMs;
            this.prevenClose = prevenClose;
            InitializeComponent();
        }

        private void Form2_Shown(object sender, EventArgs e)
        {
            ShowTime();
            timer1.Interval = 1000;
            timer1.Start();
            progressBar1.Location = new Point(XTab, 2* this.Height / 3);
            progressBar1.Width = Width - 2 * XTab;
            label1.Location = new Point((Width - label1.Width) / 2, progressBar1.Location.Y - label1.Height -YTab);
            label2.Location = new Point((Width - label2.Width) / 2, label1.Location.Y - label2.Height - YTab);

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            CurTime += timer1.Interval;
            progressBar1.Value = CurTime * 1000 / waitTimeMs;
            ShowTime();
            if (CurTime >= waitTimeMs)
            {
                timer1.Stop();
                prevenClose = false;
                Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ShowTime()
        {
            int LeftTime = (waitTimeMs - CurTime) / 1000;
            label1.Text = (LeftTime / 60).ToString()
            + ":" + String.Format("{0:00}",(LeftTime % 60));
            
        }

        private void label1_Layout(object sender, LayoutEventArgs e)
        {

        }

        private void Form2_Load(object sender, EventArgs e)
        {
            button1.Visible = !prevenClose;
        }

        private void NotificationForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = prevenClose;
        }

        private void NotificationForm_FormClosed(object sender, FormClosedEventArgs e)
        {

        }
    }
}
